package com.hhit.collaborative_learning.entity;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;

import com.hhit.collaborative_learning.utils.DBAccess;

public class Test {
	public static void main(String[] args) throws IOException {
		insertTeamUser();
	}
	
	public static void insertTeamUser(){
		Connection conn = null;
		PreparedStatement ps = null;
		try {
			conn=DBAccess.getInstance().getConn();
			ps=conn.prepareStatement("insert into team_user values(?,?,?,?,?)");
			for(int i=3;i<=40;i++){
				ps.setObject(1, i);
				ps.setObject(2, (int)(Math.random()*73)+1);
				ps.setObject(3, (int)(Math.random()*16)+1);
				Date date=new Date();
				Timestamp tt=new Timestamp(date.getTime());
				ps.setObject(4, tt);
				ps.setObject(5, "普通成员");
				ps.addBatch();
			}
			ps.executeBatch();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBAccess.getInstance().close(conn, ps, null);
		}
	}
	
	public static void insertDataComment(){
		Connection conn = null;
		PreparedStatement ps = null;
		try {
			conn=DBAccess.getInstance().getConn();
			ps=conn.prepareStatement("insert into data_comment values(?,?,?,?)");
			for(int i=1;i<=40;i++){
				ps.setObject(1, i);
				ps.setObject(2, "testtesttesttesttesttest");
				ps.setObject(3, (int)(Math.random()*73)+1);
				ps.setObject(4, 17);
				ps.addBatch();
			}
			ps.executeBatch();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBAccess.getInstance().close(conn, ps, null);
		}
	}
	public static void insertData(){
		Connection conn = null;
		PreparedStatement ps = null;
		try {
			conn=DBAccess.getInstance().getConn();
			ps=conn.prepareStatement("insert into data values(?,?,?,?,?,?,?,?,?)");
			for(int i=441;i<=480;i++){
				int minute=(int) (Math.random()*50)+10;
				int hour=(int) (Math.random()*14)+10;
				int second=(int) (Math.random()*50)+10;
				ps.setObject(1, i);
				ps.setObject(2, "测试数据"+i);
				ps.setObject(3, "这是测试用的数据");
				ps.setObject(4, "examination_authentication");
				ps.setObject(5, "考试认证");
				ps.setObject(6, (int) (Math.random()*100));
				ps.setObject(7, (int) (Math.random()*73)+1);
				ps.setObject(8, (int) (Math.random()*500));
				ps.setObject(9, "2015-04-"+((int) (Math.random()*30)+1)+" "+hour+":"+minute+":"+second);
				ps.addBatch();
			}
			ps.executeBatch();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBAccess.getInstance().close(conn, ps, null);
		}
	}
	
	public static void insert_question_comment(){
		Connection conn = null;
		PreparedStatement ps = null;
		try {
			conn=DBAccess.getInstance().getConn();
			ps=conn.prepareStatement("insert into question_comment values(?,?,?,?,?)");
			for(int i=1;i<=40;i++){
				int minute=(int) (Math.random()*50)+10;
				int hour=(int) (Math.random()*14)+10;
				int second=(int) (Math.random()*50)+10;
				ps.setObject(1, i);
				ps.setObject(2, (int)(Math.random()*70)+1);
				ps.setObject(3, "testtesttesttesttest");
				ps.setObject(4, "2015-05-12 "+hour+":"+minute+":"+second);
				ps.setObject(5, (int)(Math.random()*40)+1);
				ps.addBatch();
			}
			ps.executeBatch();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBAccess.getInstance().close(conn, ps, null);
		}
	}
	
	public static void insert_question_answer(){
		Connection conn = null;
		PreparedStatement ps = null;
		try {
			conn=DBAccess.getInstance().getConn();
			ps=conn.prepareStatement("insert into question_answer values(?,?,?,?,?,?)");
			for(int i=1;i<=40;i++){
				int minute=(int) (Math.random()*50)+10;
				int hour=(int) (Math.random()*14)+10;
				int second=(int) (Math.random()*50)+10;
				ps.setObject(1, i);
				ps.setObject(2, 13);
				ps.setObject(3, "testtesttesttesttest");
				ps.setObject(4, "2015-05-12 "+hour+":"+minute+":"+second);
				ps.setObject(5, (int)(Math.random()*40)+1);
				ps.setObject(6, 0);
				ps.addBatch();
			}
			ps.executeBatch();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBAccess.getInstance().close(conn, ps, null);
		}
	}
	
	public static void select(){
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		String str="";
		try {
			conn = DBAccess.getInstance().getConn();
//			StringBuilder sb = new StringBuilder("");
			// for(int i=0;i<60000;i++){
			// sb.append("你");
			// }
			String sql = "select * from blog";
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			if (rs.next()) {
				str=rs.getString(3);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBAccess.getInstance().close(conn, ps, null);
		}
		System.out.println("str.lenght="+str.length());
		System.out.println("str="+str);
	}

	public static void insertBlog() {
		Connection conn = null;
		PreparedStatement ps = null;
		String sql = "insert into blog values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			conn = DBAccess.getInstance().getConn();
			ps = conn.prepareStatement(sql);
			
			for(int i=201;i<221;i++){
				int flag=(int) (Math.random()*200);
				int minute=(int) (Math.random()*50)+10;
				int hour=(int) (Math.random()*14)+10;
				int second=(int) (Math.random()*50)+10;
				int userId=(int) (Math.random()*71)+1;
				ps.setObject(1, i);
				ps.setObject(2, "test"+i);
				ps.setObject(3, "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest");
				ps.setObject(4, "other");
				ps.setObject(5, "综合");
				ps.setObject(6, userId);
				ps.setObject(7, "综合");
				ps.setObject(8, "2015-04-22 "+hour+":"+minute+":"+second);
				ps.setObject(9, i-flag);
				ps.setObject(10, 0);
				ps.setObject(11, 0);
				ps.setObject(12, 0);
				if(flag%2==0){
					ps.setObject(13, 0);
				}else{
					ps.setObject(13, 1);
				}
				if(userId%2==0){
					ps.setObject(14, 0);
				}else{
					ps.setObject(14, 1);
				}
				ps.setObject(15, 1);
				ps.setObject(16, 0);
				ps.setObject(17, 0);
				ps.setObject(18, 0);
				ps.addBatch();
			}
			ps.executeBatch();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBAccess.getInstance().close(conn, ps, null);
		}
//		System.out.println("flag="+flag);
	}
	
	public static void insertBlogUserInfo(){
		Connection conn = null;
		PreparedStatement ps = null;
		String sql="insert into blog_userinfo(userId,isExpert) values(?,?)";
		try {
			conn=DBAccess.getInstance().getConn();
			ps=conn.prepareStatement(sql);
			for(int i=3;i<=63;i++){
				ps.setObject(1, i);
				ps.setObject(2, 1);
				ps.addBatch();
			}
			ps.executeBatch();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBAccess.getInstance().close(conn, ps, null);
		}
	}
	
	public static void insertUser(){
		Connection conn = null;
		PreparedStatement ps = null;
		String sql="insert into user(userId,userName,userPwd,userNickName,userIcon,userEmail) values(?,?,?,?,?,?)";
		try {
			conn=DBAccess.getInstance().getConn();
			ps=conn.prepareStatement(sql);
			for(int i=3;i<70;i++){
				ps.setObject(1, i);
				ps.setObject(2, "test"+(i-2));
				ps.setObject(3, "Aaa111");
				ps.setObject(4, "马化腾"+(i-2));
				ps.setObject(5, "20150401143244433.jpg");
				ps.setObject(6, "1105601720@qq.com");
				ps.addBatch();
			}
			ps.executeBatch();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBAccess.getInstance().close(conn, ps, null);
		}
	}
	
	public static void insertExpert(){
		Connection conn = null;
		PreparedStatement ps = null;
		String sql="insert into blog_expert values(?,?,?,?,?)";
		try {
			conn=DBAccess.getInstance().getConn();
			ps=conn.prepareStatement(sql);
			for(int i=55;i<61;i++){
				ps.setObject(1, i);
				ps.setObject(2, i+2);
				ps.setObject(3, "other");
				ps.setObject(4, "2015-04-14 12:46:00");
				ps.setObject(5, "精通other");
				ps.addBatch();
			}
			ps.executeBatch();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBAccess.getInstance().close(conn, ps, null);
		}
	}
	
	public static void insertComment(){
		Connection conn = null;
		PreparedStatement ps = null;
		String sql="insert into blog_comment(comId,comUserId,comContent,blogId,time,isDelete) values(?,?,?,?,?,?)";
		try {
			conn=DBAccess.getInstance().getConn();
			ps=conn.prepareStatement(sql);
			for(int i=1;i<=40;i++){
				ps.setObject(1, i);
				ps.setObject(2, (int)(Math.random()*67)+3);
				ps.setObject(3, "testtesttttesettsetsstsetstse");
				ps.setObject(4, 205);
				ps.setObject(5, "2015-05-06 14:"+(i+10)+":"+(i+10));
				ps.setObject(6, 0);
				ps.addBatch();
			}
			ps.executeBatch();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBAccess.getInstance().close(conn, ps, null);
		}
	}
	
	public static void insertQuestion(){
		Connection conn = null;
		PreparedStatement ps = null;
		try {
			conn=DBAccess.getInstance().getConn();
			ps=conn.prepareStatement("insert into question values(?,?,?,?,?,?,?,?,?,?)");
			for(int i=1;i<=40;i++){
				int minute=(int) (Math.random()*50)+10;
				int hour=(int) (Math.random()*14)+10;
				int second=(int) (Math.random()*50)+10;
				ps.setObject(1, i);
				ps.setObject(2, "question"+i);
				ps.setObject(3, "questionquestionquestionquestion");
				ps.setObject(4, (int)(Math.random()*70)+3);
				ps.setObject(5, "2015-05-11 "+hour+":"+minute+":"+second);
				ps.setObject(6, (int)(Math.random()*20));
				ps.setObject(7, (int)(Math.random()*10));
				ps.setObject(8, 0);
				ps.setObject(9, (int)(Math.random()*10));
				ps.setObject(10, 0);
				ps.addBatch();
			}
			ps.executeBatch();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBAccess.getInstance().close(conn, ps, null);
		}
	}
}
